<?php
require_once './vendor/autoload.php';

set_time_limit(0);
//$socketLocal = new \HemiFrame\Lib\WebSocket\WebSocket('localhost', '7002');
$socketRemote = new \HemiFrame\Lib\WebSocket\WebSocket('localhost', '7001');

//$socketRemote->on('receive', function (\HemiFrame\Lib\WebSocket\Client $client, $data) use ($socketLocal) {
//    echo $data."\n";
//    $data = [
//        'event' => 'broadcast',
//        'data' => $data
//    ];
//    $clientLocal = $socketLocal->connect();
//    $socketLocal->sendData($clientLocal, json_encode($data));
//});
$socketRemote->on('receive', function (\HemiFrame\Lib\WebSocket\Client $client, $data) {
    echo $data."\n";
});
$client = $socketRemote->connect();
$data = [
    'event' => 'ping'
];
while (true) {
    $socketRemote->sendData($client, json_encode($data));
    echo $client->getId().' ping'."\n";
    sleep(10);
}